{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "90d814f4-1a64-454b-a15b-5640228afa0f",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/rotate-list\n",
    "\n",
    "\n",
    "Runtime: 8 ms, faster than 62.07% of C++ online submissions for Rotate List.\n",
    "Memory Usage: 11.8 MB, less than 48.62% of C++ online submissions for Rotate List.\n",
    "\n",
    "\n",
    "```cpp\n",
    "class Solution {\n",
    "public:\n",
    "    ListNode* rotateRight(ListNode* head, int k) {\n",
    "      //9:07\n",
    "      vector<ListNode*> l;\n",
    "      auto node = head;\n",
    "      while (node != nullptr) {\n",
    "        l.push_back(node);\n",
    "        node = node->next;\n",
    "      }\n",
    "\n",
    "      if (l.size() == 0) {\n",
    "        return nullptr;\n",
    "      }\n",
    "\n",
    "      k = k%l.size();\n",
    "      for (int i=0; i < k; i++) {\n",
    "        auto last = l[l.size()-1]; \n",
    "        l.insert(l.begin(), last);\n",
    "        l.pop_back();\n",
    "      }\n",
    "\n",
    "      for (int i =0; i < l.size(); i++) {\n",
    "        if (i < l.size() - 1) {\n",
    "          l[i]->next = l[i+1];\n",
    "        } else {\n",
    "          l[i]->next = nullptr;\n",
    "        }\n",
    "      }\n",
    "\n",
    "      return l[0];\n",
    "      //9:15\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d54c6433-5f67-4709-b148-0527142d6e05",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "name": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
